<?php

namespace app\api\controller;

use app\common\controller\Api;
use app\admin\model\IntergalGoods;
use think\Db;
/**
 *  购物车管理
 *
 *  Author:  YSX
    Date:    2022-12-1
 */
class Integralcart extends Api
{
    // protected $noNeedLogin = ['cartInfo'];
    protected $noNeedRight = '*';

    public function _initialize()
    {
        parent::_initialize();
    }
    /*
     * 列表
    */
    public function cartInfo()
    {
        // $params = $this->params;
		if (!$this->request->isPost()) {
			return $this->error('提交方式不正确');
		}
		$member_id = $this->auth->id;
		$where['a.member_id'] = array('eq',$member_id);
		
        $data = Db::name('integral_cart as a')->where($where)
			->join('integral_goods x', 'a.integral_goods_id = x.id','left')
			->join('integral_goods_attr o', 'a.integral_goods_attr_id = o.id','left')
		    ->field('a.id,a.number,x.goods_name,x.image,x.price,x.mix_title,x.lineation_price,o.attr_name,o.price as attr_price,o.image as attr_image')
		    ->order('a.id desc')
		    ->select(); 
		
		$this->success('获取成功', $data);
    }
	/*
	 * 编辑购物车
	 */
	public function editCart()
	{
	    if (!$this->request->isPost()) {
	    	return $this->error('提交方式不正确');
	    }
		$params = $this->request->post();
		$result = Db::name('integral_cart')->where('id',$params['id'])->setField('number',$params['number']);
		// if ($result) {
		$this->success('编辑成功');
		// }
		// $this->error('编辑失败');
	}
	/*
	 * 删除购物车
	 */
	public function delCart()
	{
	    if (!$this->request->isPost()) {
	    	return $this->error('提交方式不正确');
	    }
		$params = $this->request->post();
		$result = Db::name('integral_cart')->where('id','in',$params['ids'])->delete();
		if ($result) {
			$this->success('删除成功');
		}
		$this->error('删除失败');
	}
}
